package com.java.dormitorymanager.mvc.view;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @program: DormitoryManager
 * @description: 给宿舍打分
 * @author: ShuangChenYue
 * @create: 2021-05-18 12:26
 **/
@WebServlet(value = "/ViewAddScoreToDorm")
public class ViewAddScoreToDormServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        System.out.println("点击打分按钮进入此打分页面");
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();

        out.println("<!DOCTYPE html>");
        out.println("<html lang=\"en\">");
        out.println("<head>");
        out.println("<meta charset=\"UTF-8\">");
        out.println("<title>宿舍打分</title>");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-dorm/addScoreToDorm.css\">");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-other/doIcon.css\">");
        out.println("</head>");
        out.println("<body>");
        out.println("<div id=\"divTitle\">");
        out.println("<h1 id=\"h01\">Manage Dorm</h1>");
        out.println("</div>");
        out.println("<div id=\"registerBox\">");
        out.println("<h1>Score</h1>");
        out.println("<form id=\"registerForm\" action=\"/DormitoryManager/mvc/updateScoreAfterAdd.do\" method=\"post\">");
        out.println("<table id=\"registerTable\">");
        out.println("<tr>");
        String dornum = (String) req.getAttribute("dornum");
        out.println("<td id=\"tdDornum\" colspan=\"2\"><i id=\"dornumIcon\" class=\"iconfontU\">&#xe615;</i><input id=\"inputDornum\" type=\"text\" name=\"dornum\" placeholder=\"宿舍编号\" readonly=\"readonly\" value="+dornum+"></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td id=\"tdScore\"><i id=\"ScoreIcon\" class=\"iconfontU\">&#xea3a;</i>");
        int score = (int) req.getAttribute("score");

        out.println("<select id=\"selectScore\" name=\"score\">");
        out.println("<option value ="+score+">"+score+"</option>");
        out.println("<option value =\"0\">0</option>");
        out.println("<option value =\"1\">1</option>");
        out.println("<option value =\"2\">2</option>");
        out.println("<option value =\"3\">3</option>");
        out.println("<option value =\"4\">4</option>");
        out.println("<option value =\"5\">5</option>");
        out.println("<option value =\"6\">6</option>");
        out.println("<option value =\"7\">7</option>");
        out.println("<option value =\"8\">8</option>");
        out.println("<option value =\"9\">9</option>");
        out.println("<option value =\"10\">10</option>");
        out.println("</select>");
        out.println("</td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td id=\"tdSubmit\" colspan=\"2\"><input id=\"inputSubmit\" type=\"submit\" value=\"OK\" title=\"点击评分\"></td>");
        out.println("</tr>");
        out.println("</table>");
        out.println("</form>");
        out.println("</div>");
        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();
    }
}
